﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using Vit.Web;
using Vit.Web.Models;
using Vit.Web.Services;

namespace Vit.CMS
{
    public static class PathExtension
    {
        public static string PageLink(this FileInfo file)
        {
            WebSite site = ((Vit.Web.VitApplication)HttpContext.Current.ApplicationInstance).CurrentSite;
            string path = file.FullName.Replace(site.PhysicalRootPath, "");
            path = path.Replace("\\", "!").Replace(".", "$");
            return path;
        }

        public static string DirectoryLink(this DirectoryInfo dir)
        {
            WebSite site = ((Vit.Web.VitApplication)HttpContext.Current.ApplicationInstance).CurrentSite;
            string path = dir.FullName.Replace(site.PhysicalRootPath, "");
            path = path.Replace("\\", "!").Replace(".", "$");
            return path;
        }

        public static string PageFile(this string path)
        {
            WebSite site = ((Vit.Web.VitApplication)HttpContext.Current.ApplicationInstance).CurrentSite;
            path = path.Replace("!", "\\").Replace("$", ".");
            string file = Path.Combine(site.PhysicalRootPath, path);
            return file;
        }

        public static string VirtualPagePath(this string physicalPath)
        {
            WebSite site = ((Vit.Web.VitApplication)HttpContext.Current.ApplicationInstance).CurrentSite;
            string path = physicalPath.Replace(site.PhysicalRootPath, "");
            path = path.Replace("\\", "/");
            return path;
        }
    }
}
